package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.AttendService;
import com.wuseguang.springcloud.util.DateUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 班牌人脸或刷卡考勤 前端控制器 （小程序应用）
 * </p>
 *
 * @author
 * @since 2020-03-02
 */
@RestController
@RequestMapping("/jurisdiction")
public class AttendController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private AttendService attendServiceImpl;

    /**
     * 根据班级查询学生考勤
     *
     * @param request
     * @param classId
     * @return
     */
    @RequestMapping("/findStudentAttend")
    public Result findStudentAttend(RequestParameterWrapper request,
                                    @RequestParam(value = "classId") String classId,
                                    @RequestParam(value = "dateTime", required = false) String dateTime) {
        logger.info("根据班级查询学生考勤");
        //学校id
        String schoolId = request.getParam("schoolId");

        return attendServiceImpl.findStudentAttend(classId, dateTime, schoolId);
    }

    /**
     * @描述 查询学生考勤
     * @创建人 zm
     * @创建时间 2020/3/18
     */
    @RequestMapping("/queryStudentAttend")
    public Result queryAttendAll(RequestParameterWrapper request,
                                 @RequestParam(value = "attendGroupId") String attendGroupId,
                                 @RequestParam(value = "dateTime") String dateTime,
                                 @RequestParam(value = "classId", required = false) String classId) {//格式 "1,2,3,5"
        String schoolId = request.getParam("schoolId");
        logger.info("school_id={}", schoolId);
        String gettime = DateUtil.gettime();
        if (DateUtil.getDay(gettime, dateTime) > 0) {
            return new Result();
        }
        // List<Map<String, Object>> mapList = attendServiceImpl.queryStudentAttend(attendGroupId, schoolId, dateTime, classId);
        // 考勤2.0
        List<Map<String, Object>> mapList = attendServiceImpl.queryStudentAttend2(attendGroupId, schoolId, dateTime, classId);
        return new Result(mapList);
    }

    /**
     * @描述 统计考勤数量
     * @创建人 zm
     * @创建时间 2020/5/13
     */
    @RequestMapping("/queryStudentAttendCount")
    public Result queryStudentAttendCount(RequestParameterWrapper request,
                                          @RequestParam(value = "dateTime") String dateTime,
                                          @RequestParam(value = "type") Integer type) {
        String schoolId = request.getParam("schoolId");
        logger.info("school_id={}", schoolId);
        String gettime = DateUtil.gettime();
        if (DateUtil.getDay(gettime, dateTime) > 0) {
            return new Result();
        }
        // return attendServiceImpl.queryStudentAttendCount(attendGroupId, schoolId, dateTime, classId);
        //return attendServiceImpl.querySchoolAttendCount(schoolId, dateTime, type);
        return attendServiceImpl.queryStudentAttendCount2(schoolId, dateTime, type);
    }

    /**
     * @描述 查该学校考勤时间段
     * @创建人 zm
     * @创建时间 2020/6/9
     */
    @RequestMapping("/queryTimeSlot")
    public Result queryTimeSlot(RequestParameterWrapper request, @RequestParam(value = "dateTime") String dateTime) {//格式 "1,2,3,5"
        String schoolId = request.getParam("schoolId");
        logger.info("school_id={}", schoolId);
        return attendServiceImpl.queryTimeSlot(schoolId, dateTime);
    }


    /**
     * @描述 根据考勤组id查年级班级信息
     * @创建人 zm
     * @创建时间 2020/5/14
     */
    @RequestMapping("/attendGroupClass")
    public Result attendGroupClass(RequestParameterWrapper request,
                                   @RequestParam(value = "attendGroupId") String attendGroupId) {//格式 "1,2,3,5"
        String schoolId = request.getParam("schoolId");
        logger.info("school_id={}", schoolId);
        return attendServiceImpl.attendGroupClass(attendGroupId, schoolId);
    }

}

